package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.vo.GoodsTypeList;
import com.atguigu.jxc.service.GoodsService;
import com.atguigu.jxc.service.GoodsTypeService;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author luojia
 * @create 2022-01-01 22:03
 */
@RestController
@RequestMapping("goodsType")
public class GoodsTypeController {

    @Autowired
    private GoodsTypeService goodsTypeService;

    @Autowired
    private GoodsService goodsService;

    /**
     * 查询商品所有分类
     * @return
     */
    @PostMapping("loadGoodsType")
    public String queryCategories(){
        List<GoodsTypeList> goodsTypeLists = goodsTypeService.queryCategories();
        Gson gson = new Gson();
        return gson.toJson(goodsTypeLists);
    }

    /**
     * 删除商品的类别
     * @param goodsTypeId
     * @return
     */
    @PostMapping("delete")
    public ServiceVO goodsTypeVoDelete(@RequestParam("goodsTypeId") Integer  goodsTypeId){
        this.goodsService.goodsTypeVoDelete(goodsTypeId);
        return new ServiceVO(100,"请求成功",null);
    }
    /**
     * 添加商品的类别
     * @param goodsTypeName
     * @param pId
     * @return
     */
    @PostMapping("save")
    public ServiceVO goodsTypeVoSave(@RequestParam("goodsTypeName") String  goodsTypeName,@RequestParam("pId") Integer  pId){
        this.goodsService.goodsTypeVoSave(goodsTypeName,pId);
        return new ServiceVO(100,"请求成功",null);
    }
}
